feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation#5254
Conversation
Add SentryKafkaProducerWrapper that overrides doSend to create queue.publish spans for all KafkaTemplate send operations. Injects sentry-trace, baggage, and sentry-task-enqueued-time headers for distributed tracing and receive latency calculation. Add SentryKafkaProducerBeanPostProcessor to automatically wrap KafkaTemplate beans. Co-Authored-By: Claude <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Internal Changes 🔧Deps
Other
🤖 This preview updates automatically when you update the PR. |
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- [Queue Instrumentation 3] Add Kafka producer instrumentation ([#5254](https://github.com/getsentry/sentry-java/pull/5254))If none of the above apply, you can opt out of this check by adding |
Sentry Build Distribution
|
Performance metrics 🚀
|
…oducerInterceptor Replace the KafkaTemplate subclass approach with a Kafka-native ProducerInterceptor. The BeanPostProcessor now sets the interceptor on the existing KafkaTemplate instead of replacing the bean, which preserves any custom configuration on the template. Existing customer interceptors are composed using Spring's CompositeProducerInterceptor. If reflection fails to read the existing interceptor, a warning is logged. Co-Authored-By: Claude <noreply@anthropic.com>
TransactionContext constructor requires ScopesAdapter.getOptions() to be non-null for thread checker access. Add initForTest/close to ensure Sentry is properly initialized during tests. Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fdb3a03. Configure here.
9830c0c
into
feat/queue-instrumentation

PR Stack (Queue Instrumentation)
📜 Description
Add Kafka producer instrumentation to
sentry-spring-jakarta:SentryKafkaProducerWrapper— overridesdoSendto createqueue.publishspans for allKafkaTemplatesend operations. Injectssentry-trace,baggage, andsentry-task-enqueued-timeheaders for distributed tracing and receive latency calculation.SentryKafkaProducerBeanPostProcessor— automatically wrapsKafkaTemplatebeans.💡 Motivation and Context
Producer-side instrumentation is needed to create publish spans and inject trace propagation headers into Kafka messages.
💚 How did you test it?
Unit tests for
SentryKafkaProducerWrapperandSentryKafkaProducerBeanPostProcessor.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps